<%@ page import="bw.news.*" %>
<%@ page import="bw.util.Log" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>

<%

  NewsManager manager = NewsManager.getInstance();

  String message = "";

  String newsSourceId = request.getParameter( "newsSourceId" );
  NewsSource s = manager.getNewsSourceForId( newsSourceId );

  String pluginName = request.getParameter( "pluginName" );
  if ( pluginName != null && pluginName.length() > 0 )
  {
      try {
        Class c = Class.forName( pluginName );
	if ( c != null ) {
          s.setPluginName( pluginName );	
	  s.sync();
	  message = "Success";
        }
      }
      catch ( Exception ex )  {
        Log.getInstance().write( "Problem updating " + s.getName(), ex );
        message = "Problem updating " + s.getName() + ": " + ex.getMessage();
      }
  } else if ( pluginName != null && pluginName.length() == 0 ) {
    if ( s.getPluginName() != null ) {
      s.setPluginName( null );
      s.sync();
      message = "Success";
    }
  }

  Iterator sources = manager.getNewsSources();
  
%>

<html>
<head>
<title>WebDash Plugin Config</title>

<body>

<p>
<%= message %>
</p>

<p>
Update NewsSource Plugin
</p>

<%
  while ( sources.hasNext() ) {
    NewsSource source = (NewsSource) sources.next();
%>
<form>
<%= source.getName() %>
&nbsp;&nbsp;
<input type="text" size="30" name="pluginName" value="<%= ( source.getPluginName() != null ? source.getPluginName() : "" ) %>">
&nbsp;&nbsp;
<input type="submit" value="Update Plugin">
<input type="hidden" name="newsSourceId" value="<%= source.getId() %>">
</form>
<% } %>

</body>
</html>